/*=========================================================================

Program:   Virtual Surgery
Language:  C++
Date:      2009-9-1
Version:   0.1
Mail:		   nelfylee@gmail.com

Copyright (c) 2009 Nelfy Lee. All rights reserved.

=========================================================================*/
#ifndef _VIEW3D_H_
#define _VIEW3D_H_

#include "View.h"
#include "VolumeSource.h"
#include "InteractorStyles.h"

#include "vtkImageWriter.h"
#include "vtkDataSetToImageFilter.h"

class Source;

class vtkAreaPicker;
class vtkImageCast;
class vtkPiecewiseFunction;
class vtkColorTransferFunction;
class vtkVolumeProperty;
class vtkVolumeRayCastCompositeFunction;
class vtkVolumeRayCastMapper;
class vtkVolume;
class vtkActor;
class vtkImageData;
class vtkOutlineFilter;
class vtkPolyDataMapper;
class vtkContourFilter;
class QLabel;
class QToolButton;
class vtkDataSetSurfaceFilter;
class vtkImageMarchingCubes;
class vtkSmoothPolyDataFilter;
class vtkRenderedAreaPicker;
class vtkInteractorStyleRubberBandPick;
class vtkExtractSelectedFrustum;
class vtkInteractorStyleTrackballCamera;
class vtkInteractorStyleTrackball;

#include "itkImage.h"


enum DisplayMode
{
	dmNormal,
	dmPicking,
	dmProperPicking
};

class View3D : public View
{
	Q_OBJECT
public:
	View3D(const QString &name,int id);

	void updateRealTimeSlicing(vtkProp *prop);
	void selectProper(vtkProp *prop){}
	vtkRenderedAreaPicker* getPicker() {return m_areaPicker;}
	void switchMode(DisplayMode mode);
	void cameraLinked(bool flag);

	vtkRenderWindowInteractor* interactor();

	// If source is NULL, stop slicing
// 	void setRealTimeSlicing(Source*);
// 	void updateRealTimeSlicing();

	void setProperPickingMode(vtkCommand *);

public slots:
	void slotStartRealTimeSlicing();
	void slotStopRealTimeSlicing();
	void slotClearRealTimePropers();

	void slotLeftButtonPressed(vtkObject *obj, unsigned long vtk_even);
	void slotLeftButtonReleased(vtkObject *obj, unsigned long vtk_even);
	void slotMouseMove(vtkObject *obj);
	void slotRightButtonPressed(vtkObject *obj);
	void slotRightButtonReleased(vtkObject *obj);
	void slotMouseEnter(vtkObject *obj);
	void slotMouseLeave(vtkObject *obj);
	void slotMiddleButtonReleased(vtkObject*);

	void slotLinkedCameraMoving();

	void slotProcessKeyEvent(vtkObject* caller,
		unsigned long eventId,
		void* clientData,
		void* callData);
	// Update displaying of current source
	//void update();

signals:
	void startPicking();
	void emitLinkedCameraMoving();
	void emitStartCutting();
	void emitStopCutting();
	void emitDoCut();
	void emitKeyEvent(QKeyEvent*);


private slots:
	void slotCutting(bool);


private:
	void initInternalObjects();

private:
	bool m_isRealTimeSlicing;
	bool m_isNeedResetCamera;
	bool m_cameraLinked;
	DisplayMode m_displayMode;

	QLabel *label;

	QToolButton *m_btnCutting;

	QList<vtkProp*> m_rtPropList;		// real time proper list

  	vtkRenderedAreaPicker *m_areaPicker;
  	vtkInteractorStyleTrackballCamera *m_interactorStyleTrackballCamera;
  	vtkExtractSelectedFrustum *m_extractor;
  	vtkActor *m_selectedActor;
};

#endif
